import Vue from 'vue'
import Router from 'vue-router'
// import dangerMenu from './modules/dangerMenu'
import dangerMenu from './modules/dangerMenu'
import configuration from './modules/configuration'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  /* 模版路由 */
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    hidden: true,
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },
  /* 模版路由 */

  // 风险部分

  // 制度规范
  {
    path: '/',
    component: Layout,
    redirect: 'riskMenu/dashboard/rules'
    // redirect: 'riskMenu/riskpoint/point'
    // redirect: 'riskMenu/riskpoint/dangerous'

  },
  {
    path: '/riskMenu/dashboard',
    name: 'dashboard',
    component: Layout,
    meta: { title: '制度规范', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'rules',
        name: 'Rules',
        component: () => import('@/views/riskMenu/dashboard/rules'),
        meta: { title: '规章制度', icon: 'table' }
      },
      {
        path: 'responsibility',
        name: 'Responsibility',
        component: () => import('@/views/riskMenu/dashboard/responsibility'),
        meta: { title: '责任体系', icon: 'tree' }
      }
    ]
  },
  // 标准数据库
  {
    path: '/riskMenu/standard',
    component: Layout,
    name: 'Sandard',
    meta: { title: '标准数据库', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'equipment',
        name: 'Equipment',
        component: () => import('@/views/riskMenu/standard/equipment'),
        meta: { title: '设备设施库', icon: 'form' }
      },
      {
        path: 'task',
        name: 'Task',
        component: () => import('@/views/riskMenu/standard/task'),
        meta: { title: '作业活动库', icon: 'form' }
      }
    ]
  },
  // 风险分布图
  {
    path: '/riskMenu/risk',
    component: Layout,
    name: 'Risk',
    meta: { title: '风险分布图', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'visual',
        name: 'Visual',
        component: () => import('@/views/riskMenu/risk/visual'),
        meta: { title: '可视化编辑', icon: 'form' }
      },
      {
        path: 'fourcolor',
        name: 'Fourcolor',
        component: () => import('@/views/riskMenu/risk/fourcolor'),
        meta: { title: '四色风险地图', icon: 'form' }
      }
    ]
  },
  // 风险点
  {
    path: '/riskMenu/riskpoint',
    component: Layout,
    name: 'Riskpoint',
    meta: { title: '风险点', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'facilities',
        name: 'Facilities',
        component: () => import('@/views/riskMenu/riskpoint/facilities'),
        meta: { title: '设备设施', icon: 'form' }
      },
      {
        path: 'point',
        name: 'Point',
        component: () => import('@/views/riskMenu/riskpoint/point'),
        meta: { title: '风险点', icon: 'form' }
      },
      {
        path: 'inspection',
        name: 'Inspection',
        component: () => import('@/views/riskMenu/riskpoint/inspection'),
        meta: { title: '检查项目', icon: 'form' }
      },
      {
        path: 'dangerous',
        name: 'Dangerous',
        component: () => import('@/views/riskMenu/riskpoint/dangerous'),
        meta: { title: '风险', icon: 'form' }
      },
      {
        path: 'control',
        name: 'Control',
        component: () => import('@/views/riskMenu/riskpoint/Control'),
        meta: { title: '管控措施', icon: 'form' }
      },
      {
        path: 'Warning',
        name: 'warning',
        component: () => import('@/views/riskMenu/riskpoint/warning'),
        meta: { title: '实时预警记录', icon: 'form' }
      },
      {
        path: 'qr-code',
        name: 'QR-code',
        component: () => import('@/views/riskMenu/riskpoint/qr-code'),
        meta: { title: '二维码管理', icon: 'form' }
      },
    ]
  },

  // 历史预警记录
  {
    path: '/riskMenu/history',
    component: Layout,
    name: 'History',
    alwaysShow: true,
    meta: { title: '历史预警记录', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'operation',
        name: 'Operation',
        component: () => import('@/views/riskMenu/history/operation'),
        meta: { title: '预警操作', icon: 'form' }
      }
    ]
  },

  // 统计风险
  {
    path: '/riskMenu/census',
    component: Layout,
    name: 'Census',
    alwaysShow: true,
    meta: { title: '统计风险', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'censuspoint',
        name: 'censuspoint',
        component: () => import('@/views/riskMenu/census/censuspoint'),
        meta: { title: '风险点统计', icon: 'form' }
      }

    ]
  },

  // 台账清单
  {
    path: '/riskMenu/accountlist',
    component: Layout,
    name: 'Accountlist',
    alwaysShow: true,
    meta: { title: '台账清单', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'duty',
        name: 'duty',
        component: () => import('@/views/riskMenu/accountlist/duty'),
        meta: { title: '风险分级责任清单', icon: 'form' }
      },
      {
        path: 'measures',
        name: 'Measures',
        component: () => import('@/views/riskMenu/accountlist/measures'),
        meta: { title: '风险管控措施清单', icon: 'form' }
      },

    ]
  },

  // 引入隐患的路由配置
  ...dangerMenu,
  ...configuration,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
